#ggsave("3prime_Val_t6A_plot.pdf", plot_threePrime, width = 10, height = 8, device = cairo_pdf)

set.seed(123)  # Set a seed for reproducibility
set_up("RNA_A", "AAACCGUUACCAUUACUGAG", "Data/sgRNA/20nt_data/20ntRNA_134_931_hydrolysis_5uL_5 min_injection.xlsx", "synthetic_RNA", 6000, 0)
## [1] "Starting the analysis on RNA_A with file location in Data/sgRNA/20nt_data/20ntRNA_134_931_hydrolysis_5uL_5 min_injection.xlsx, the sample is classified as synthetic_RNA with a intact mass higher than 6000"
prophet_A5 = prophet(df, theo_5)
prophet_A3 = prophet(df, theo_3)
set_up("RNA_B", "UAUUCAAGUUACACUCAAGA", "Data/sgRNA/20nt_data/20ntRNA_134_931_hydrolysis_5uL_5 min_injection.xlsx", "synthetic_RNA", 6000, 0)
## [1] "Starting the analysis on RNA_B with file location in Data/sgRNA/20nt_data/20ntRNA_134_931_hydrolysis_5uL_5 min_injection.xlsx, the sample is classified as synthetic_RNA with a intact mass higher than 6000"
prophet_B5 = prophet(df, theo_5)
prophet_B3 = prophet(df, theo_3)
set_up("RNA_C", "GCGUACAUCUUCCCCUUUAU", "Data/sgRNA/20nt_data/20ntRNA_134_931_hydrolysis_5uL_5 min_injection.xlsx", "synthetic_RNA", 6000, 0)
## [1] "Starting the analysis on RNA_C with file location in Data/sgRNA/20nt_data/20ntRNA_134_931_hydrolysis_5uL_5 min_injection.xlsx, the sample is classified as synthetic_RNA with a intact mass higher than 6000"
prophet_C5 = prophet(df, theo_5)
prophet_C3 = prophet(df, theo_3)

prophet_A5 = prophet_A5 %>% 
  mutate(ladder_type = "A5")

prophet_A3 = prophet_A3 %>% 
  mutate(ladder_type = "A3")

prophet_B5 = prophet_B5 %>% 
  mutate(ladder_type = "B5")

prophet_B3 = prophet_B3 %>% 
  mutate(ladder_type = "B3")

prophet_C5 = prophet_C5 %>% 
  mutate(ladder_type = "C5")

prophet_C3 = prophet_C3 %>% 
  mutate(ladder_type = "C3")

prophet_all = rbind(prophet_A3, prophet_A5, prophet_B3, prophet_B5, prophet_C3, prophet_C5) %>% 
  select(monoisotopic_mass, apex_rt, sum_intensity, relative_abundance, ladder_type, base_name, n_position)


# Filter df1
filtered_df <- df%>%
  filter(!monoisotopic_mass %in% prophet_all$monoisotopic_mass) %>% 
  filter(monoisotopic_mass < 6400) %>% 
  filter(sum_intensity < 100000) #intensity less than 100000, excluding ladder points

sampled_df <- filtered_df %>% sample_n(100) %>% 
  mutate(ladder_type = "noise", base_name = "", n_position = 1)

figure1_df = rbind(prophet_all, sampled_df)
data <- prophet_all %>% slice(-c(19, 37, 56, 74))

# 绘制 3D 散点图
plot_ly(data, x = ~monoisotopic_mass, y = ~apex_rt, z = ~sum_intensity,
               type = "scatter3d", mode = "markers",
               marker = list(size = 4, color = "#20B2AA"))
# 保存为 PDF
pdf("3d_plot_ggplot_style.pdf", width = 8, height = 6)

plot_ly(
  data,
  x = ~monoisotopic_mass,
  y = ~apex_rt,
  z = ~sum_intensity,
  type = "scatter3d",
  mode = "markers",
  marker = list(
    size = 4,
    color = "#20B2AA",
    line = list(width = 0)  # 移除标记边框
  )
) %>%
layout(
  scene = list(
    # 完全隐藏所有坐标轴
    xaxis = list(visible = FALSE),
    yaxis = list(visible = FALSE),
    zaxis = list(visible = FALSE),
    
    # 透明背景设置
    bgcolor = 'rgba(0,0,0,0)',
    
    # 移除3D场景的所有装饰
    camera = list(
      up = list(x = 0, y = 0, z = 1),
      center = list(x = 0, y = 0, z = 0),
      eye = list(x = 1.25, y = 1.25, z = 1.25)
    )
  ),
  
  # 全局透明设置
  paper_bgcolor = 'rgba(0,0,0,0)',
  plot_bgcolor = 'rgba(0,0,0,0)',
  
  # 移除所有边距
  margin = list(l = 0, r = 0, b = 0, t = 0)
)